<!-- src/components/PropertyEditor.vue -->
<template>
  <div>
    <h3>属性面板</h3>
    <el-form class="form" label-position="top">
      <el-form-item v-if="form.x" label="X">
        <el-input-number v-model="form.x" :step="1" @change="applyChanges" />
      </el-form-item>

      <el-form-item v-if="form.y" label="Y">
        <el-input-number v-model="form.y" :step="1" @change="applyChanges" />
      </el-form-item>

      <el-form-item v-if="form.width" label="宽度">
        <el-input-number v-model="form.width" :step="1" @change="applyChanges" />
      </el-form-item>

      <el-form-item v-if="form.height" label="高度">
        <el-input-number v-model="form.height" :step="1" @change="applyChanges" />
      </el-form-item>

      <el-form-item v-if="form.rx" label="圆角">
        <el-input-number v-model="form.rx" :step="1" @change="applyChanges" />
      </el-form-item>
      <!-- cx，cy， r -->
      <el-form-item v-if="form.cx" label="圆心X">
        <el-input-number v-model="form.cx" :step="1" @change="applyChanges" />
      </el-form-item>
      <el-form-item v-if="form.cy" label="圆心Y">
        <el-input-number v-model="form.cy" :step="1" @change="applyChanges" />
      </el-form-item>
      <el-form-item v-if="form.r" label="半径">
        <el-input-number v-model="form.r" :step="1" @change="applyChanges" />
      </el-form-item>

      <el-form-item v-if="form.fill" label="填充色">
        <el-color-picker v-model="form.fill" show-alpha @change="applyChanges" />
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import { ref, watch } from 'vue'

const props = defineProps({
  shape: Object,
})

const emit = defineEmits(['update-shape'])

const form = ref({})

watch(
  () => props.shape,
  (shape) => {
    form.value = {
      ...shape,
    }
  },
  { immediate: true },
)

function applyChanges() {
  emit('update-shape', { ...form.value })
}
</script>

<style scoped>
.form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 300px;
}
</style>
